import Vue from 'vue'
import Router from 'vue-router'
//整页面加载 网速他太慢
// import Home from "../components/Home.vue"
// import Profile from "../components/Profile.vue"
// import Categroy from "../components/Categroy.vue"
// import Shappingcar from "../components/Shapingcar.vue"

//路由懒加载技术
const Home = () =>
    import ('../components/Home');
const Profile = () =>
    import ('../components/Profile');
const Categroy = () =>
    import ('../components/Categroy');
const Shapingcar = () =>
    import ('../components/Shapingcar');
const Carchild = () =>
    import ('../components/carChild');
const Car2 = () =>
    import ('../components/car2')

//阻止当前页面跳当前页报错问题 button按钮点击切换路由
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}


Vue.use(Router)
export default new Router({
        mode: 'history',
        routes: [{
                path: '/',
                redirect: 'home'
            },
            {
                path: '/home',
                component: Home,
                meta: {
                    title: '首页'
                },
            },
            {
                path: '/car',
                component: Shapingcar,
                meta: {
                    title: '购物车'
                },
            },
            {
                path: '/categrog',
                component: Categroy,
                meta: {
                    title: '分类'
                },
            },
            {
                path: '/profile',
                component: Profile,
                meta: {
                    title: '我的'
                },
            },
        ],
    })
    // 路由添跳转显示对应的标题
    // router.beforeEach((to, form, next) => {
    // document.title = to.matched[0].meta.title
    //     next();
    // })